package com.edu.cq02.controller;



import com.edu.cq02.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("ajax")
public class ajaxloginController {

    @RequestMapping("login")
    @ResponseBody
    public ResultData login( User user) {
            System.out.println(user.getUsername()+"   "+   user.getPassword());
        ResultData rd = new ResultData();
        int i = 1/0;

        rd.setCode(0);
        rd.setMsg("登录成功");
        return rd;
    }

    @RequestMapping("loginjson")
    @ResponseBody
    public ResultData loginjson(@RequestBody User user, HttpSession httpSession) {
        System.out.println(user.getUsername()+"   "+   user.getPassword());
        httpSession.setAttribute("userinfo", user);
        ResultData rd = new ResultData();
        rd.setCode(0);
        rd.setMsg("登录成功");
        return rd;
    }

    @RequestMapping("tohome")
    public String tohome() {
        int i = 1/0;

        return "home";
    }


}

